#include "GlobalPrec.h"
#include "CCEGLView.h"
#include "SimpleAudioEngine.h"

USING_NS_CC;
using namespace CocosDenshion;

CSDelegate::CSDelegate()
{
}

CSDelegate::~CSDelegate()
{
	SimpleAudioEngine::end();
	GTask->release();
}

bool CSDelegate::applicationDidFinishLaunching()
{
	CCDirector *pDirector = CCDirector::sharedDirector();
	pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
	pDirector->setAnimationInterval(1.0 / 60);

	GameLayerConfigMgr::StaticInit();
	GameSceneMgr::StaticInit();

	GTask = new TaskThreadPool;
	GTask->autorelease();
	pDirector->getScheduler()->scheduleSelector(schedule_selector(TaskThreadPool::DoLoop),GTask,0.0f,false);
	CCTextureCache::sharedTextureCache();
	OnDidFinishLaunching();

	

	return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void CSDelegate::applicationDidEnterBackground()
{
	CCDirector::sharedDirector()->stopAnimation();

	SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void CSDelegate::applicationWillEnterForeground()
{
	CCDirector::sharedDirector()->startAnimation();

	SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
